﻿#if NETSTANDARD2_0 || NETCOREAPP3_0
#else
using Longbow.Configuration;
using System.ComponentModel;
using System.Configuration;
#endif

namespace Longbow.Cache
{
#if NETSTANDARD2_0 || NETCOREAPP3_0
    /// <summary>
    /// 缓存配置项定义类
    /// </summary>
    public class CacheOption : ICacheOption
    {
        /// <summary>
        /// 获得/设置 是否启用 默认值 true 启用本配置项
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 获得/设置 缓存键值，配置文件中的 Key
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 获得/设置 缓存时间 单位毫秒 默认为 5000
        /// </summary>
        public int Interval { get; set; } = 5000;

        /// <summary>
        /// 获得/设置 缓存描述
        /// </summary>
        public string Desc { get; set; }

        /// <summary>
        /// 获得/设置 缓存是否自动延长默认值 false
        /// </summary>
        public bool SlidingExpiration { get; set; }

        /// <summary>
        /// 获得/设置 缓存键值 缓存时真正使用的 Key
        /// </summary>
        public string CacheKey { get; set; }
    }
#else
    /// <summary>
    ///
    /// </summary>
    public class CacheOption : LgbConfigurationElement, ICacheOption
    {
        /// <summary>
        /// 获得/设置 缓存时间 单位毫秒 默认为 5000
        /// </summary>
        [ConfigurationProperty("interval")]
        [DefaultValue(5000)]
        public int Interval { get { return (int)this["interval"]; } set { this["interval"] = value; } }

        /// <summary>
        /// 获得/设置 缓存描述
        /// </summary>
        [ConfigurationProperty("desc")]
        public string Desc { get { return (string)this["desc"]; } set { this["desc"] = value; } }

        /// <summary>
        /// 获得/设置 缓存是否自动延长默认值 false
        /// </summary>
        [ConfigurationProperty("slidingExpiration")]
        [DefaultValue(false)]
        public bool SlidingExpiration { get { return (bool)this["slidingExpiration"]; } set { this["slidingExpiration"] = value; } }

        /// <summary>
        /// 获得/设置 缓存键值 缓存时真正使用的Key
        /// </summary>
        public string CacheKey { get; set; }
    }
#endif
}
